<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        /**
         * 判断年份是否为润年
         *
         * @param {Number} year
         */
        function isLeapYear(year) {
            return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
        }
        /**
         * 获取某一年份的某一月份的天数
         *
         * @param {Number} year
         * @param {Number} month
         */
        function getMonthDays(year, month) {
            return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month] || (isLeapYear(year) ? 29 : 28);
        }
        26
        /**
         * 获取某年的某天是第几周
         * @param {Number} y
         * @param {Number} m
         * @param {Number} d
         * @returns {Number}
         */

        var time, week, checkDate = new Date(new Date());
        console.log(checkDate);
        checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
        time = checkDate.getTime();
        checkDate.setMonth(0);
        checkDate.setDate(1);
        week = Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
        console.log("今天是本年当中的第" + week + "“周”");



        // 方法3
        function theWeek() {
            var totalDays = 0;
            now = new Date();
            years = now.getYear()
            if (years < 1000)
                years += 1900
            var days = new Array(12);
            days[0] = 31;
            days[2] = 31;
            days[3] = 30;
            days[4] = 31;
            days[5] = 30;
            days[6] = 31;
            days[7] = 31;
            days[8] = 30;
            days[9] = 31;
            days[10] = 30;
            days[11] = 31;

            //判断是否为闰年，针对2月的天数进行计算
            if (Math.round(now.getYear() / 4) == now.getYear() / 4) {
                days[1] = 29
            } else {
                days[1] = 28
            }
            if (now.getMonth() == 0) {
                totalDays = totalDays + now.getDate();
            } else {
                var curMonth = now.getMonth();
                for (var count = 1; count <= curMonth; count++) {
                    totalDays = totalDays + days[count - 1];
                }
                totalDays = totalDays + now.getDate();
            }
            //得到第几周
            var week = Math.round(totalDays / 7);
            return week;
        }
        console.log(theWeek())
    </script>
</body>

</html>